#include "Globals.h"

#include <cassert>
#include <cstdlib>
#include <ctime>

#include "main/D3DData.h"
#include "main/WindowManager.h"

#include "managers/PipelineStatesManager.h"
#include "managers/SettingsManager.h"
#include "managers/ShadersManager.h"
#include "managers/ShaderResourcesManager.h"

SettingsManager* Globals::gSettingsManager = nullptr;
HINSTANCE Globals::gApp;
WindowData* Globals::gWindowData = nullptr;
Direct3DData* Globals::gD3D = nullptr;
ShadersManager* Globals::gShaders = nullptr;
ShaderResources* Globals::gResources = nullptr;
PipelineStates* Globals::gPipeline = nullptr;
Camera Globals::gCamera;
MouseProperties* Globals::mMouseProperties = nullptr;
bool Globals::gAppIsClosing = false;
bool Globals::gExecCS = true;

void 
Globals::init() {
	gSettingsManager = new SettingsManager(L"configs/configs.json");

	gWindowData = new WindowData();

	gD3D = new Direct3DData(*gWindowData);
	
	gShaders = new ShadersManager();

	gResources = new ShaderResources();

	gPipeline = new PipelineStates();

	mMouseProperties = new MouseProperties();

	srand(static_cast<unsigned int> (time(nullptr)));
}

void 
Globals::destroy() {
	delete mMouseProperties;
	
	delete gPipeline;

	delete gResources;
	
	delete gShaders;	

	delete gD3D;

	delete gWindowData;

	delete gSettingsManager;
}